package com.superman.supermarket.client.composite.comment;

import java.util.HashMap;
import java.util.Map;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.Widget;
import com.superman.mvpframe.client.utils.StringUtils;
import com.superman.mvpframe.client.widget.lazy.LazyImage;
import com.superman.supermarket.client.composite.IUIModule;
import com.superman.supermarket.client.widget.star.CommentStarList;

/**
 * 待评价商品模块
 * 
 * @author superman
 * @version 2018年8月15日下午11:51:12
 */
public class CommentSkuModule extends Composite implements IUIModule {

	interface CommentSkuModuleUiBinder extends UiBinder<Widget, CommentSkuModule> {
	}

	private static CommentSkuModuleUiBinder uiBinder = GWT.create(CommentSkuModuleUiBinder.class);

	@UiField
	LazyImage image;
	@UiField
	TextArea input;
	private String skuId;

	@UiField
	CommentStarList star;

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年8月15日 下午11:51:09
	 */
	public CommentSkuModule() {
		initWidget(uiBinder.createAndBindUi(this));
		star.addStar(5, true);
		star.setValue(5);
		input.getElement().setAttribute("placeHolder", "在这里输入你对宝贝的评价");
	}

	@Override
	public Map<String, Object> getData() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("SKU_ID", skuId);
		map.put("COMMENT_SCORE", star.getValue());
		if (!StringUtils.isEmpty(input.getValue().trim()))
			map.put("CONTENT", input.getValue().trim());
		return map;
	}

	@Override
	public void setData(Map<String, Object> map) {
		this.skuId = String.valueOf(map.get("SKU_ID"));
		image.setUrl(String.valueOf(map.get("SKU_PIC")));
	}

}
